/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package su.samlib.informer.database.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author rikland
 */
@Entity
@Table(name = "\"user\"")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findByUserId", query = "SELECT u FROM User u WHERE u.userId = :userId"),
    @NamedQuery(name = "User.findByUserEmail", query = "SELECT u FROM User u WHERE u.userEmail = :userEmail"),
    @NamedQuery(name = "User.findByUserPasswd", query = "SELECT u FROM User u WHERE u.userPasswd = :userPasswd"),
    @NamedQuery(name = "User.findByUserLogin", query = "SELECT u FROM User u WHERE u.userLogin = :userLogin")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "user_id", nullable = false)
//    @GeneratedValue(generator="user_user_id_seq")
//    @SequenceGenerator(name="user_user_id_seq",sequenceName="user_user_id_seq",allocationSize=1)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer userId;
    @Basic(optional = false)
    @Column(name = "user_email", nullable = false, length = 100)
    private String userEmail;
    @Column(name = "user_passwd", length = 50)
    private String userPasswd;
    @Column(name = "user_login", length = 100)
    private String userLogin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<UserAuthors> userAuthorsList;

    public User() {
    }

    public User(Integer userId) {
        this.userId = userId;
    }

    public User(Integer userId, String userEmail) {
        this.userId = userId;
        this.userEmail = userEmail;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserPasswd() {
        return userPasswd;
    }

    public void setUserPasswd(String userPasswd) {
        this.userPasswd = userPasswd;
    }

    public String getUserLogin() {
        return userLogin;
    }

    public void setUserLogin(String userLogin) {
        this.userLogin = userLogin;
    }

    @XmlTransient
    public List<UserAuthors> getUserAuthorsList() {
        return userAuthorsList;
    }

    public void setUserAuthorsList(List<UserAuthors> userAuthorsList) {
        this.userAuthorsList = userAuthorsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "su.samlib.informer.database.model.User[ userId=" + userId + " ]";
    }
    
}
